#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;



int countInversions_insertionSort(int a[], int length) {
	int count = 0;
	for (int i = 1; i < length; i++) {
		int key = a[i];
		int j;
		for (j = i - 1; (j >= 0) && (a[j] > key); j--) {
			a[j + 1] = a[j];
			count++;
		}
		a[j + 1] = key;
	}
	return count;
}


int main() {
	cin >> n;
	for (int i = 0; i < n; i ++ )
		cin >> w[i];
	for (int i = 0; i < n; i ++ )
		for (int j = 0; j < i; j ++ )
			if (w[j] > w[i])
				ans[w[i]] ++ ;

	int sum = 0;
	for (int i = 1; i <= n; i ++ ) {
		cout << ans[i] / 2 + 1 << ' ';
		sum += ans[i];
	}

	cout << endl << sum << endl;
	return 0;
}



